package com.itheima.stringdemo;
/*
 *
 *      字符串常用方法:
 *
 *
 *
 * */

public class StringDemo02 {
    public static void main(String[] args) {
        //目标:快速熟悉String提供的处理字符串的常用方法
        //1.获取字符创的长度
        String name = "ab黑马陈平安888";
        System.out.println(name.length());
        //2.提供字符串某个索引的位置处的字符
        System.out.println(name.charAt(6));
        //遍历字串
        for (int i = 0; i < name.length(); i++) {
            System.out.print(name.charAt(i) + " ");
        }
        System.out.println("-------------------");
        //3.把字符串转换成字符数组
        char[] chars = name.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            System.out.print(c + " ");
        }
        System.out.println("-------------------");
        //4.比较字符串的内容,返回值类型时boolean ,(精准比较)
        String s1 = "黑马001chen";
        String s2 = "黑马001chen";
        String s3 = "黑马001cheN";
        System.out.println(s1.equals(s2));
        System.out.println(s2.equals(s3));

        //5.比较字符串的内容,(忽略大小写)
        System.out.println(s1.equalsIgnoreCase(s2));//true
        System.out.println(s3.equalsIgnoreCase(s2));//false
        //6.截取字符串的内容(包前不包后)-->百分之99,都是不包后
        String s4 = "chenjungaoauds";
        System.out.println(s4.substring(1, 2));

        //7.从当前索引一直截取到字符串末尾
        System.out.println(s4.substring(4));
        //8.把字符串中的某个内容,替换成新的内容,并返回新的字符串对象给我们
        String info = "这个游戏真是个垃圾,sb,去你大爷的,还我血汗钱30块,垃圾";
        String replace = info.replace("垃圾", "**").replace("sb", "**");
        System.out.println(replace);
        //9.判断字符串中是否包含某个关键字
        System.out.println(info.contains("垃圾"));
        //10.判断字符串是否以某个字符串开头
        //startWith()
        info.startsWith("这个游戏");//true
        info.startsWith("垃圾");//false
        //endWith() 判断以什么结尾
        info.endsWith("垃圾");//true
        info.endsWith("s");//false
        info.endsWith("圾");//ture

        //11.把字符串按照指定的内容分隔成多个字符串
        //放到一个字符串数组中返回给我们
        String result = "chen,jun,hao";
        String[] split = result.split(",");
        for (int i = 0; i < split.length; i++) {
            System.out.println(split[i]);
        }
    }
}
